package netssl;

import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactorySpi;
import javax.net.ssl.ManagerFactoryParameters;
import java.security.*;

public class J_SSLKeyManagerFactory extends KeyManagerFactorySpi {
    protected String m_alias;//密钥项的别名
    protected KeyStore m_keystore;//密钥库
    protected char[] m_storepass;//密钥库的密码
    protected char[] m_keypass;//密钥项的密码

    public J_SSLKeyManagerFactory(){
        m_alias = System.getProperty("Self.alias");
        m_keypass = System.getProperty("Self.keypass").toCharArray();
    }
      public J_SSLKeyManagerFactory(String alias,char[] keypass){
        m_alias = alias;
        m_keypass = keypass;
    }

    @Override
    protected void engineInit(KeyStore keyStore, char[] password) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
        m_keystore = keyStore;
        m_storepass = password;
    }

    @Override
    protected void engineInit(ManagerFactoryParameters managerFactoryParameters) throws InvalidAlgorithmParameterException {

    }

    @Override
    protected KeyManager[] engineGetKeyManagers() {
        J_SSLKeyManager[] skm = new J_SSLKeyManager[1];
        skm[0] = new J_SSLKeyManager(m_keystore,m_alias,m_storepass,m_keypass);
        return skm;
    }
}
